//
//  PMCircleShape.m
//  PezMonkey
//
//  Created by Spence DiNicolantonio on 10/29/09.
//  Copyright 2009 Necrosoft. All rights reserved.
//

/**
 * A subclass of PMShape for representing circular collision shapes.
 */

#import "PMCircleShape.h"
#import "PMBody.h"


@implementation PMCircleShape


#pragma mark -
#pragma mark Init

/**
 * Returns a PMCircleShape object initialized to correspond to a given PMBody 
 * object. The shape is set to a given radius, centered around the body's center 
 * of gravity.
 */
- (id)initWithBody:(PMBody *)aBody radius:(PMFloat)radius {
	return [self initWithBody:aBody radius:radius center:PMVectZero];
}

/**
 * Returns a PMCircleShape object initialized to correspond to a given PMBody 
 * object. The shape is set to a given radius, centered around a given offset 
 * relative to the body's center of gravity.
 */
- (id)initWithBody:(PMBody *)aBody radius:(PMFloat)radius center:(PMVect)center {
	if (![super init])
		return nil;
	
	// allocate and initialize cpShape
	shape = cpCircleShapeNew(aBody.cpBody, radius, center);
	self.body = aBody;
	
	return self;
}


#pragma mark -
#pragma mark Getters

/**
 * Returns the receiver's center point relative to its corresponding PMBody.
 */
- (PMVect)center {
	return (PMVect) ((cpCircleShape *) shape)->c;
}

/**
 * Returns the receiver's radius.
 */
- (PMFloat)radius {
	return ((cpCircleShape *) shape)->r;
}


#pragma mark -
#pragma mark Setters

/**
 * Sets the receiver's center point offset to a given point, relative to its 
 * corresponding PMBody's center of gravity. Use of this method is not recommended,
 * as it could result in anomalous behavior.
 */
- (void)setCenter:(PMVect)center {
	((cpCircleShape *) shape)->c = center;
}

/**
 * Sets the receiver's radius to a given value. Use of this method is not recommended,
 * as it could result in anomalous behavior.
 */
- (void)setRadius:(PMFloat)radius {
	((cpCircleShape *) shape)->r = radius;
}

@end
